<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once dirname(__FILE__)."/Localization.class.php";
require_once dirname(__FILE__)."/Races.class.php";
require_once dirname(__FILE__)."/Classes.class.php";

define("CHARACTER_SORT_METHOD_USES_RACE", 1);
define("CHARACTER_SORT_METHOD_USES_CLASS", 2);
define("CHARACTER_SORT_METHOD_USES_LEVEL", 3);

class CharacterSortMethod
{
	static private $localization;
	static private $races;
	static private $classes;
	
	private $id;
	private $locale;
	private $icon;
	private $big_icon;
	private $group_by_sql_query;
	private $divide_by;
	private $uses;
	
	static function Initialize()
	{
		if ( empty(self::$localization) )
		{
			self::$localization = Localization::GetInstance();
			self::$races = Races::GetInstance();
			self::$classes = Classes::GetInstance();
		}
	}
	
	function CharacterSortMethod($id, $locale, $icon, $big_icon, $group_by_sql_query, $divide_by, $uses = null)
	{
		$this->id = $id;
		$this->locale = $locale;
		$this->icon = $icon;
		$this->big_icon = $big_icon;
		$this->group_by_sql_query = $group_by_sql_query;
		$this->divide_by = $divide_by;
		$this->uses = $uses;
	}
	
	function GetId()
	{
		return $this->id;
	}
	
	function GetName()
	{
		return self::$localization->Get($this->locale);
	}
	
	function GetSmallIcon()
	{
		return $this->icon;
	}
	
	function GetBigIcon()
	{
		return $this->big_icon;
	}
	
	function GetGroupBySqlQuery()
	{
		return $this->group_by_sql_query;
	}
	
	function IsDivided()
	{
		if ($this->divide_by != null)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function GetDivideField()
	{
		return $this->divide_by;
	}
	
	function GetSubSectionName( $character_data )
	{
		if ($this->uses == CHARACTER_SORT_METHOD_USES_RACE)
		{
			return self::$races->GetLiteral( $character_data[$this->GetDivideField()] );
		}
		elseif ($this->uses == CHARACTER_SORT_METHOD_USES_CLASS)
		{
			return self::$classes->GetLiteral( $character_data[$this->GetDivideField()] );
		}
		elseif ($this->uses == CHARACTER_SORT_METHOD_USES_LEVEL)
		{
			return "<span>".$character_data[$this->GetDivideField()]."</span>";
		}
		else
		{
			return $character_data[$this->GetDivideField()];
		}
	}
}

?>